﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using JewelLibrary;

namespace JewelForm
{
    public partial class JewelForm : Form
    {
        double ruby_carat = 0.4, diamond_carat = 0.1, emerald_carat = 0.91, obsidian_carat = 2, jasper_carat = 1.4;
        double ruby_price = 3590, diamond_price = 7000, emerald_price = 42480, obsidian_price = 1197, jasper_price = 1200;
        List<AbstractJewel> JewelList = new List<AbstractJewel>();
        
        public JewelForm()
        {
            InitializeComponent();
        }

        private void JewelForm_Load(object sender, EventArgs e)
        {
            RubyNumeric.Minimum = -10;
            DiamondNumeric.Minimum = 0;
            EmeraldNumeric.Minimum = 0;
            ObsidianNumeric.Minimum = 0;
            JasperNumeric.Minimum = 0;

           // Ruby_carat.Text = ruby_carat.ToString();
            textBox1.Text = ruby_carat.ToString();
            Diamond_carat.Text = diamond_carat.ToString();
            Emerald_carat.Text = emerald_carat.ToString();
            Obsidian_carat.Text = obsidian_carat.ToString();
            Jasper_carat.Text = jasper_carat.ToString();

            Ruby_cost.Text = (ruby_price * System.Convert.ToDouble(RubyNumeric.Value)).ToString();
            Diamond_cost.Text = (diamond_price * System.Convert.ToDouble(DiamondNumeric.Value)).ToString();
            Emerald_cost.Text = (emerald_price * System.Convert.ToDouble(EmeraldNumeric.Value)).ToString();
            Obsidian_cost.Text = (obsidian_price * System.Convert.ToDouble(ObsidianNumeric.Value)).ToString();
            Jasper_cost.Text = (jasper_price * System.Convert.ToDouble(JasperNumeric.Value)).ToString();

            
            CreatorPrecious[] precious = new CreatorPrecious[3];
            CreatorNotPrecious[] notprecious = new CreatorNotPrecious[2];
            precious[0] = new RubyCreator();
            precious[1] = new DiamondCreator();
            precious[2] = new EmeraldCreator();

            notprecious[0] = new ObsidianCreator();
            notprecious[1] = new JasperCreator();

            foreach (CreatorPrecious pr in precious)
            {
                if (pr is RubyCreator)
                    JewelList.Add(pr.FactoryMethod(ruby_price, ruby_carat, "Рубин", "Стеклянный"));
                else if (pr is DiamondCreator)
                    JewelList.Add(pr.FactoryMethod(diamond_price, diamond_carat, "Бриллиант", "Сверкающий"));
                else if (pr is EmeraldCreator)
                    JewelList.Add(pr.FactoryMethod(emerald_price, emerald_carat, "Изумруд", "Стеклянный"));
            }

            foreach (CreatorNotPrecious npr in notprecious)
            {
                if (npr is ObsidianCreator)
                    JewelList.Add(npr.FactoryMethod(obsidian_price, obsidian_carat, "Обсидиан", "Стеклянный"));
                else if (npr is JasperCreator)
                    JewelList.Add(npr.FactoryMethod(jasper_price, jasper_carat, "Яшма", "Стеклянный"));
            }


        }


        private void Create_necklace_Click(object sender, EventArgs e)
        {
            JewelList[0].Carat = System.Convert.ToDouble(textBox1.Text);
            string RequiredStones = "0," + RubyNumeric.Value.ToString() +
                ",1," + DiamondNumeric.Value.ToString() +
                ",2," + EmeraldNumeric.Value.ToString() +
                ",3," + ObsidianNumeric.Value.ToString() +
                ",4," + JasperNumeric.Value.ToString();
            Necklace necklace = new Necklace();
            string result = necklace.CountCaratAndCost(JewelList, RequiredStones);
            string[] ar = result.Split(';');
            Necklace_carat.Text = ar[0];
            Necklace_cost.Text = ar[1];
        }

        private void RubyNumericChange(object sender, EventArgs e)
        {

            Ruby_cost.Text = (ruby_price * System.Convert.ToDouble(RubyNumeric.Value)).ToString();
        }

        private void DiamondNumericChange(object sender, EventArgs e)
        {
            Diamond_cost.Text = (diamond_price * System.Convert.ToDouble(DiamondNumeric.Value)).ToString();
        }

        private void EmeraldNumericChange(object sender, EventArgs e)
        {
            Emerald_cost.Text = (emerald_price * System.Convert.ToDouble(EmeraldNumeric.Value)).ToString();
        }

        private void ObsidianNumericChange(object sender, EventArgs e)
        {
            Obsidian_cost.Text = (obsidian_price * System.Convert.ToDouble(ObsidianNumeric.Value)).ToString();
        }

        private void JasperNumericChange(object sender, EventArgs e)
        {
            Jasper_cost.Text = (jasper_price * System.Convert.ToDouble(JasperNumeric.Value)).ToString();
        }
    }
}
